package Practice;

import Event.MyJFrame;

import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class JFrameTest extends JFrame {

    private int count = 0;
    private AddText text = new AddText("账号",100,100,this);
    private AddText text1 = new AddText("密码",100,200,this);

    public JFrameTest(){
        this.setLayout(null);

        AddButton addButton = new AddButton("登录",200,400,this);

        addButton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                login();
            }
        });


        this.setSize(500,600);
        this.setVisible(true);
        this.setDefaultCloseOperation(3);
        this.setLocationRelativeTo(null);
    }

    private void login(){
        if (text.getText().equals("001")&&text1.getText().equals("111")){
            JOptionPane.showMessageDialog(null,"登录成功");

            this.dispose();
            new MyJFrame();

        }else {
            this.count++;
            JOptionPane.showMessageDialog(null, "账号或密码有误，重新输入");
            if (this.count>=3){
                JOptionPane.showMessageDialog(null,"非法用户");
                System.exit(0);
            }
        }

    }


    public static void main(String[] args) {
        new JFrameTest();
    }
}
